"""
3. 随机数生成与猜测
编写一个Python程序，使用random库生成一个1到10之间的随机整数，然后让用户猜测这个数字。用户有3次猜测机会。
"""

import random

num = random.randint(1, 10)
right = False

for i in range(3):
    i_num = int(input("输入数字："))
    if num == i_num:
        print("猜对了！")
        right = True
        break

if not right:
    print("没有猜对")
import random

random_num = random.randint(1, 10)
guess_times = 3

while guess_times > 0:
    guess = int(input("请输入您猜测的数字(1 到 10 之间): "))
    if guess == random_num:
        print("恭喜您猜对了！")
        break
    elif guess > random_num:
        print("您猜大了，还有", guess_times - 1, "次机会")
    else:
        print("您猜小了，还有", guess_times - 1, "次机会")
    guess_times -= 1

if guess_times == 0:
    print("很遗憾，您没有猜对，正确的数字是", random_num)